package com.qianfeng.xinyihezi.xinyihezi.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.qianfeng.xinyihezi.xinyihezi.R;
import com.qianfeng.xinyihezi.xinyihezi.model.LeftData;

/**
 * Created by Tcoy on 2016/11/14.
 */

public class ClassiftLeftAdapter extends BaseAdapter {
    private String TAG = getClass().getSimpleName();
    private LeftData mLeftData;
    private LayoutInflater inflater;
    private int currPosotion;

    public ClassiftLeftAdapter(Context context, LeftData mLeftData) {
        this.mLeftData = mLeftData;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if (mLeftData.getClassiftLeftDataList() == null) {
            return 0;
        }
        return mLeftData.getClassiftLeftDataList().size();
    }

    @Override
    public Object getItem(int position) {
        return mLeftData.getClassiftLeftDataList().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.left_classift_item_layout, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.viewFlag.setTag(position);
        holder.tvClassiftName.setTag(position);
        holder.tvClassiftName.setText(mLeftData.getClassiftLeftDataList().get(position).getName());

        if (currPosotion == position) {
            holder.tvClassiftName.setTextColor(Color.parseColor("#FF5656"));
            holder.viewFlag.setVisibility(View.VISIBLE);
            convertView.setBackgroundColor(Color.parseColor("#FFFFFF"));
        } else {
            holder.tvClassiftName.setTextColor(Color.parseColor("#444444"));
            holder.viewFlag.setVisibility(View.GONE);
            convertView.setBackgroundColor(Color.parseColor("#F8F8F8"));
        }

        return convertView;
    }

    public class ViewHolder {
        private View viewFlag;
        private TextView tvClassiftName;


        public ViewHolder(View view) {
            viewFlag = view.findViewById(R.id.view_flag);
            tvClassiftName = (TextView) view.findViewById(R.id.textView_classiftName);
        }
    }

    public void setCurrItemPosition(int position) {
        this.currPosotion = position;
    }
}
